﻿
@{
    Layout = null;
}

<div>
    <div class="col-3 pr-0" style="display: none">
        <label id="SAMPLE-SelectEquipment-SDId">@ViewData["SampleAnalyteId"]</label>
        <label id="SAMPLE-SelectEquipment-Parent-ModalID">@ViewData["ModalID"]</label>
    </div>
</div>
<div class="input-group">
    <div class="col-12 pr-0 pl-0">
        <span class="input-group-text font-rfs-modal border-radius-noright">设备列表</span>
    </div>
</div>
<div class="table-responsive-sm modal-table-shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="height: 60vh;">
    <table id="SAMPLE-SelectEquipment-Type" class="table table-striped table-bordered-modal table-sm table-hover">
        <thead>
            <tr>
                <th></th>
                <th>设备类型</th>
            </tr>
        </thead>
        <tbody style="font-size: calc(0.6em + 0.1vw) !important"></tbody>
    </table>
</div>
<div class="text-right" style="padding-top: 5px;">
    <button id="SAMPLE-SelectEquipment-confirm" type="button" class="btn btn-primary font-rfs-modal">确定</button>
    <button id="SAMPLE-SelectEquipment-cancel" type="button" class="btn btn-info font-rfs-modal">取消</button>
</div>

<script>

    $(document).ready(function () {
        LoadEqType();
    });

    function SetTypeEnableCortrol(value, row, index) {
        var strHtml = "";
        if (row.use) {
            strHtml = "<input type='checkbox' checked />";
        } else {
            strHtml = "<input type='checkbox' />";
        }

        return strHtml;
    }

    function LoadEqType() {
        var columns = [{ field: "use", width: "5%", align: "center", formatter: SetTypeEnableCortrol }, { field: "type" }];

        $('#SAMPLE-SelectEquipment-Type').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#SAMPLE-SelectEquipment-Type').bootstrapTable({
            method: 'post',
            url: "GetEquipmentTypeList",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    SampleAnalyteId: $("#SAMPLE-SelectEquipment-SDId").html(),  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                };
                return data;
            }, //参数
            queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
            onClickRow: function (row, $element, field) {
                $("#SAMPLE-SelectEquipment-Type").find("tbody").find("tr").each(function () {
                    $(this).removeClass('changeblueColor');
                });
                $element.addClass("changeblueColor");
                SelectSpec_specId = row.id;
            },
            silent: true,  //刷新事件必须设置
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {  //没有匹配的结果
                return '无符合条件的记录';
            },
            onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
            },
            onLoadError: function (data) {
                $('#SAMPLE-SelectEquipment-Type').bootstrapTable('removeAll');
            }
        });
    }

    $("#SAMPLE-SelectEquipment-cancel").click(function (event) {
        var modalID = $("#SAMPLE-SelectEquipment-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

    $("#SAMPLE-SelectEquipment-confirm").click(function () {
        var st = ""; // 获取表格中已选择的设备字符串
        $("#SAMPLE-SelectEquipment-Type > tbody tr").each(function(){
            if ($(this).find("td:eq(0)").find("input").prop("checked")) {
                st = st + "," + $(this).find("td:eq(1)").text();
            }
        });
        st = st.substring(1, st.lengths);

        $.post("postUpdateEquipmentTypeList", {
            SampleAnalyteId: $("#SAMPLE-SelectEquipment-SDId").html(),
            EquipmentTypeList: st
        }, function (data) {
            alert(data);
            $("#SAMPLE-SelectEquipment-cancel").click();
        });
    });

</script>
